(function(){
    $.getJSON('/module/link_product/index.php?token=<?=$token?>&appid=<?=$appid?>&signature=<?=md5($token.$appid.$pid);?>&pid=<?=$pid?>')
        .done(function(data){
            if (data.status==0) {
                return false;
            } else {
                var prodTabs   = '<ul class="packageTab">',
                    ticketHtml = '',
                    width = 160,
                    cnt = 0;
                for (var j in data) {
                    var     productObj = data[j]['product'],
                        priceObj   = data[j]['price'],
                        linksObj   = productObj['link_ids'],
                        price      = 0,
                        buyLink    = '',
                        ticketList = '',
                        style_width = width,
                        cur        = cnt==0 ? 'cur' : '';
                    cnt += 1;

                    prodTabs   += '<li class="tab_li_'+cur+'" data-tab="tab_'+j+'">套餐'+ cnt +'</li>';

                    ticketList += '<li><p><img src="'+productObj['l_img']+ '"/></p>'
                        + productObj['l_title']
                        + '<br/>'+productObj['t_title']+'X'
                        + productObj['num']+'(张)</li>';
                    if (priceObj['jsprice']>0) {
                        price = priceObj['jsprice'] / 100;
                        buyLink = '<a class="btnBuy" href="productOrder.html?pid='
                            + productObj['pid']+'&aid='+productObj['aid']+'">立即购买</a>';
                    } else {
                        buyLink = '<span class="btnBuy disable">立即购买</span>';
                    }
                    for (var i in linksObj) {
                        style_width += width;
                        ticketList  += '<li class="plus">+</li>'
                            + '<li><p><img src="'+linksObj[i]['l_img']+'"/></p>'
                            + linksObj[i]['l_title']+'<br/>'
                            + linksObj[i]['t_title']+'X'+linksObj[i]['num']+'(张)</li>';
                    }
                    ticketHtml += '<div id="tab_'+j+'" class="tab_div tab_div_'+cur+'">'
                               + '<div class="tab-left">'
                               + '<ul class="link_tickets" style="width:'+style_width+'px;">'
                               + ticketList
                               + '</ul></div><div class="tab-right buyLine"><p>套票价格：'
                               + '<span class="price">￥'+price+'</span><span class="price_txt">起</span><br/>'
                               + '<span class="price_detail">价格以游玩日期当天为准</span></p>'
                               + buyLink
                               + '<p class="applyer">供应商:'+productObj['aid_name']+'</p>'
                               + '</div></div>';
                }
                prodTabs += '</ul>';
                var htmlStr = '<h3 class="title">'
                    + '<span class="title">推荐购买</span>'
                    + '</h3>'
                    + '<div class="box">'
                    + (cnt>1 ? prodTabs :'')
                    + ticketHtml
                    + '</div>';
                $("#RecommendProducts").show().html(htmlStr);
            }
        });
    $(".packageTab li").live('click', function(){
        var $tab_ul = $("#"+$(this).attr('data-tab'));
        $tab_ul.siblings('div').removeClass('tab_div_cur');
        $tab_ul.addClass('tab_div_cur');
        $(this).siblings('li').removeClass('tab_li_cur');
        $(this).addClass('tab_li_cur');
    });
})();